package com.xuanyuanxinyu.view.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView

/**
 * @author ken.luo
 * @version V1.0
 * @FileName:
 * @Description:
 * @date 2023/4/4
 * @email 424533553@qq.com
 */
abstract class BaseAdapter<T>(private val layout : Int,diffCallback : DiffUtil.ItemCallback<T>) : ListAdapter<T,BaseHolder<T>>(diffCallback) {
    override fun onCreateViewHolder(parent : ViewGroup,viewType : Int) : BaseHolder<T> {
        val view = LayoutInflater.from(parent.context).inflate(layout,parent,false)
        return BaseHolder(view)
    }
    
    override fun onBindViewHolder(holder : BaseHolder<T>,position : Int) {
        bindUi(holder.itemView,getItem(position))
    }
    
    /**
     *     var binding : ViewDataBinding? = null
     *    binding = DataBindingUtil.bind(holder.itemView)
     */
    abstract fun bindUi(itemView : View,t : T)
    
    override fun submitList(list : MutableList<T>?) {
        super.submitList(list)
    }
}


class BaseHolder<T>(itemView : View) : RecyclerView.ViewHolder(itemView) {
//    var mBinding : ViewDataBinding? = DataBindingUtil.bind(itemView)
//    var data : T? = null
//
//    fun setData(t : T) {
//        data = t
//    }
}
